OpenFileDialog
FileName$ = OpenFileDialog(Title$, DefaultFile$, Filter$, [FilterIndex], [MultiSelect])
 
Parameters:

    Title$=the dialog's title
    DefaultFile$=the initial file name
    Filter$=the filter string
    [FilterIndex]=the initially selected filter
    [MultiSelect]=allow multiselect 1 or not 0
Returns:

    FileName$=the filename selected by the user
 

     OpenFileDialog shows a standard "OpenFile" dialog.

The function returns the filename the user has selected. Use the GetFileDialogNextFile$ function to iterate through the other files if you allowed multi selection.

      * Title$ = the text displayed in the title bar of the dialog
      * DefaultFile$ = The default file displayed in the dialog. If you specify a full path it will also open the corresponding folder in the dialog.
      * Filter$ = the filter string (see below for more details).
      * FilterIndex = the filter that is initially active starting from 1 to the number of filters defined. This is an optional parameter and defaults to 1
      * Multiselect = set this parameter to 1 if you want to allow the user to pick multiple files. This is optional and defaults to 0, not allowing multiple selections of files.

The Filter$ string allows you to limit the file types that are displayed in the dialog. A filter string looks like this "Text files (*.txt)|*.TXT". The part before the "|" character describes the filter. This part is also shown in the dialog. The part after "|" is the actual filter. In this case only files with the extension "TXT" are shown. You can combine multiple filters for one description by seperating them with a semicolon (;). For example a filter that displays files with the extension "jpg" and "jpeg" would look like this "JPEG Images|*.jpg;*.jpeg". Lastly you can combine multiple description/filter pairs with a "|" character. In order to load text files or jpeg files a filter use this filter: "Text files|*.TXT|JPEG Images|*.jpg;*.jpeg".


FACTS:

      * This dialog is not asynchronous, so the PlayBasic application will halt while the dialog is open.
      * The dialog function returns a NULL string if no file was selected or the user selects cancel.




  
; Inlcude the Dialogs library in this program
  #Include "PBDialogs2"
  
  
; Title Of the Dialog
  Title$="Load A Text File"
  
; Pre-seed the file name we're expecting to find
  Filename$="Some Cool FIle.txt"
  
  
; Filter$="" ; No Filter show all files
  Filter$     ="(*.TXT)|*.TXT"          ; Only TXT files
;     Filter$     ="(*.PNG)|*.PNG"          ; Only PNG files
;     Filter$     ="(*.BMP)|*.BMP"          ; Only BMP Files
;     Filter$     ="(*.Jpeg)|*.JPG"          ; Only JPG files
;         Filter$ ="(*.Images)|*.JPG;*.bmp;*.PNG;*gif"   ; Mixture of image files
  
  
; Call the dialog
  File$=OpenFileDialog(Title$,Filename$,Filter$)
  
  
; Display the file you selected
  Print "You Selected "
  
; Display the Info about this file$
  If FileExist(file$)
     Print "Path:"+FIle$
     Print "Size:"+Str$(FileSize(File$))+" Bytes"
  Else
     Print "No file Was Selected"
  EndIf
  
  // Display the screen & wait for a key press to end
  Sync
  WaitKey
  




 
Related Info: FolderDialog | GetFileDialogFilterIndex | GetFileDialogNextFile$ | SaveFileDialog :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com